package com.qf.smsplatform.monitor.config;

import org.apache.shardingsphere.elasticjob.reg.base.CoordinatorRegistryCenter;
import org.apache.shardingsphere.elasticjob.reg.zookeeper.ZookeeperConfiguration;
import org.apache.shardingsphere.elasticjob.reg.zookeeper.ZookeeperRegistryCenter;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Author: LeeRui
 * 2021/2/3 下午 8:32
 **/
@Configuration
public class ZookeeperConfig {

    @Value("${zookeeper.serverList}")
    private String serverList;

    //连接Zookeeper
    @Bean
    public CoordinatorRegistryCenter zookeeperRegistryCenter() {
        // 关闭sasl校验,避免超时问题
        System.setProperty("zookeeper.sasl.client","false");
        CoordinatorRegistryCenter regCenter = new ZookeeperRegistryCenter(new ZookeeperConfiguration(serverList, "sms-platform-job"));
        regCenter.init();
        return regCenter;
    }

    @Bean
    public CoordinatorRegistryCenter coordinatorRegistryCenter() {
        // 关闭sasl校验,避免超时问题
        System.setProperty("zookeeper.sasl.client","false");
        CoordinatorRegistryCenter regCenter = new ZookeeperRegistryCenter(new ZookeeperConfiguration(serverList, "gatewayFeeMessageJob"));
        regCenter.init();
        return regCenter;
    }
}
